package com.cwvs.cat.adapter;

import java.util.List;

import net.tsz.afinal.FinalBitmap;

import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cwvs.cat.ClubChatRoomActivity;
import com.cwvs.cat.FoundActiveDetailActivity;
import com.cwvs.cat.R;
import com.cwvs.cat.bean.MsgActive;

public class MsgActiveAdapter  extends BaseAdapter {

	private Activity mContext;
	private List<MsgActive> list_contact;
	private LayoutInflater inflater;
	private FinalBitmap fb;

	public MsgActiveAdapter() {
		// TODO Auto-generated constructor stub
	}

	public MsgActiveAdapter(Activity ac, List<MsgActive> list) {
		// TODO Auto-generated constructor stub
		this.mContext=ac;
		this.inflater = LayoutInflater.from(ac);
		this.list_contact = list;
		fb = FinalBitmap.create(ac);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list_contact.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list_contact.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewholder;
		if(convertView==null){
			convertView = inflater.inflate(R.layout.item_list_msg_active, null);
			viewholder = new ViewHolder();
			viewholder.txt_active_message_name=(TextView) convertView.findViewById(R.id.txt_active_message_name);
			viewholder.time=(TextView) convertView.findViewById(R.id.time);
			viewholder.active_img=(ImageView) convertView.findViewById(R.id.active_img);
			convertView.setTag(viewholder);

		}else{
			viewholder = (ViewHolder) convertView.getTag();
		}
		viewholder.txt_active_message_name.setText(list_contact.get(position).nickname);
		viewholder.time.setText(list_contact.get(position).created);
		
		if (!list_contact.get(position).avatar.equals("")&&!list_contact.get(position).avatar.equals("null")) {
			fb.display(viewholder.active_img, list_contact.get(position).avatar);
		}
		
		convertView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
			//	Intent intent=new Intent();
			//	intent.setClass(mContext, FoundActiveDetailActivity.class);
			//	mContext.startActivity(intent);
			}
		});
		return convertView;
	}

	class ViewHolder {
		TextView txt_active_message_name,time;
		ImageView active_img;
	}

}
